<template>
  <el-row>
    <el-col :span="12">
      <el-form :model="form" :rules="rules" ref="form" label-width="100px">
        <el-form-item label="用户名称" prop="userName">
          <el-input v-model="form.userName"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.realName"></el-input>
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱地址" prop="email">
          <el-input v-model="form.email"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">确认修改</el-button>
          <el-button @click="$router.go(-1)">取消</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
  import {userOneself, editUserOneself} from "@/api/oneseIf-centre";

  /**
   *{ 个人基本信息编辑 }
   * @param:
   * @author: 宋康
   * @DateTime: 2022/7/1
   */
  export default {
    name: "PersonalBasicInfoEdit",
    data() {
      return {
        form: {
          uid: "",
          loginName: "",
          userName: "",
          realName: "",
          phone: "",
          email: "",
          organizations: null,
          createdTime: "",
        },
        rules: {
          userName: [
            {required: true, message: '请输入用户名称', trigger: 'blur'},
            {min: 1, max: 128, message: '长度在 1 到 128 个字符', trigger: 'blur'}
          ],
          realName: [
            {min: 1, max: 128, message: '长度在 1 到 128 个字符', trigger: 'blur'}
          ],
          phone: [
            {min: 1, max: 128, message: '长度在 1 到 128 个字符', trigger: 'blur'}
          ],
          email: [
            {min: 1, max: 128, message: '长度在 1 到 128 个字符', trigger: 'blur'}
          ],
        }
      }
    },
    methods: {
      /**
       * {获取个人信息}
       *
       * @author: 宋康
       * @date: 2022/8/17 17:35
       */
      queryUserOneself() {
        userOneself().then(res => {
          if (res.status && res.data) {
            this.form = {
              ...res.data
            }
          }
        })
      },
      /**
       * {修改个人信息}
       *
       * @author: 宋康
       * @date: 2022/8/17 17:39
       */
      submitForm() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.form.id = this.form.uid;
            editUserOneself(this.form).then(res => {
              if (res.status) {
                this.$XModal.alert({
                  content: '编辑成功',
                  status: 'success',
                });
              } else {
                this.$XModal.alert({
                  content: res['msg'],
                  status: 'error',
                })
              }
            })
          } else {
            return false;
          }
        });
      }
    },
    mounted() {
      this.queryUserOneself();
    }
  }
</script>

<style scoped>

</style>
